package edu.centenary.centenaryController;
import java.util.*;
import java.io.*;

public class Nearest{
	public static void main(String[] args)throws IOException, FileNotFoundException{
		ArrayList<BodyPart> bodyParts = new ArrayList<BodyPart>();
		ArrayList<BodyPart> people = new ArrayList<BodyPart>();
		
		Scanner scan = new Scanner(new File(args[0]));
		while(scan.hasNext()){
			BodyPart bp = new BodyPart(scan.next(),scan.nextDouble(),scan.nextDouble(),scan.nextDouble());
			System.out.println(bp);
			bodyParts.add(bp);
		}
		Scanner scan2 = new Scanner(new File(args[1]));
		while(scan2.hasNext()){
			BodyPart bp = new BodyPart(scan2.next(),scan2.nextDouble(),scan2.nextDouble(),scan2.nextDouble());
			System.out.println(bp);
			people.add(bp);
		}
		
		
			for(BodyPart bp: bodyParts){
				double minimum = bp.distance(people.get(0));
				//Crisis Averted!
				int c = bp.getCenter();
				
				//For each datapoint, find the closest center
				for(int i = 0; i < people.size(); i++){
					//System.out.println("For loop.  i is " + i);
					if(bp.distance(people.get(i)) < minimum){
						minimum = bp.distance(people.get(i));
						//System.out.println("Minimum is:"+minimum +" i is " + i);
						bp.setCenter(i);
						c = bp.getCenter();
					}
				}
				
				bp.setGroup(c);
				
				System.out.println("" + bp + " is part of group " + c);
			}
			
			
	}
}